#learning GLMs #tutorial from http://www.statmethods.net/advstats/glm.html #survival analysis #load library(lung) - lung cancer patient survival #create a surv object survobj<-with(lung,Surv(time,status)) #Surv creates a survival object as a response variable in a model formula; time = for right censored data; status = ending time of interval #plot survival distribution of the total sample #Kaplan-Meier estimator fit0<-survfit(survobj~1, data=lung) #survfit creates survival curves from a formula or model summary(fit0) plot(fit0,xlab='survival time in days', ylab='% surviving', yscale=100, main='survival distribution (overall)') #think this plots survival by time with upper and lower 95% CI #compare survival dist of men and women fit1<-survfit(survobj~sex, data=lung) plot(fit1, xlab='survival time in days', ylab='% surviving', yscale=100, col=c('red', 'blue'), main='survival distributions by gender') legend('topright', title='gender', c('male', 'female'), fill=c('red', 'blue')) #test for differences between male and female #survival curves (logrank test) survdiff(survobj~sex,data=lung) #does Chi square #predict male survival from age and medical scores MaleMod<-coxph(survobj~age+ph.ecog+ph.karno+pat.karno,data=lung, subset=sex==1)